// 测试晶体模式下原子隐藏/显示功能的脚本
console.log('Testing crystal mode atom toggle functionality...')

// 模拟隐藏元素集合
const hiddenElements = new Set()

// 模拟晶体模式状态
const crystalMode = true
const unitCells = 3; // 3x3x3晶胞

// 测试函数：切换元素可见性
function toggleElementVisibility (element) {
  console.log(`\n=== Toggling element: ${element} ===`)
  console.log(`Crystal mode: ${crystalMode}`)
  console.log(`Unit cells: ${unitCells}`)
  console.log(`Current hidden elements:`, Array.from(hiddenElements))

  if (hiddenElements.has(element)) {
    // 显示元素
    hiddenElements.delete(element)
    console.log(`Showing element: ${element}`)

    if (crystalMode) {
      console.log('Crystal mode detected - re-rendering entire structure')
      console.log(`Would render ${unitCells}x${unitCells}x${unitCells} unit cells for element ${element}`)
    } else {
      console.log('Single unit cell mode - adding individual atoms')
    }
  } else {
    // 隐藏元素
    hiddenElements.add(element)
    console.log(`Hiding element: ${element}`)
    console.log(`Removing all atoms of element ${element} from scene`)
  }

  console.log(`Updated hidden elements:`, Array.from(hiddenElements))
  return true
}

// 测试用例
console.log('\n🧪 Test Case 1: Hide Silicon atoms')
toggleElementVisibility('Si')

console.log('\n🧪 Test Case 2: Show Silicon atoms (should re-render in crystal mode)')
toggleElementVisibility('Si')

console.log('\n🧪 Test Case 3: Hide Oxygen atoms')
toggleElementVisibility('O')

console.log('\n🧪 Test Case 4: Show Oxygen atoms (should re-render in crystal mode)')
toggleElementVisibility('O')

console.log('\n🧪 Test Case 5: Test with single unit cell mode')
const singleCellMode = false
if (!singleCellMode) {
  console.log('Single cell mode - would add individual atoms')
} else {
  console.log('Crystal mode - would re-render entire structure')
}

console.log('\n✅ Test completed. Check console output for expected behavior:')
console.log('1. In crystal mode, showing elements should trigger full re-render')
console.log('2. Hidden elements should be properly tracked')
console.log('3. Individual atoms should not be added in crystal mode (full re-render instead)')
